package cn.bs.busuo.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.content.pojo.entity.ContentSightArticle;
import cn.bs.busuo.content.pojo.param.SightArticleAddNewParam;
import cn.bs.busuo.content.pojo.vo.ContentSightArticleListBySortVO;
import cn.bs.busuo.content.service.SightArticleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Feng
 * @since: 2023/12/6
 */
@RestController
@Slf4j
@RequestMapping("/admin/content/sightArticle")
@Api(tags = "2.景点文章")
public class SightArticController {

    @Autowired
    private SightArticleService sightArticleService;

    @PostMapping("/addNewSightArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("发布景点文章")
    @ApiOperationSupport(order = 100)
    public JsonResult addNewSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @Valid SightArticleAddNewParam sightArticleAddNewParam) {
        sightArticleService.addNewSightArticle(currentPrincipal, sightArticleAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/deleteSightArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("删除景点文章")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        sightArticleService.deleteArticle(ids);
        return JsonResult.ok();
    }

    @PostMapping("/setIsRecommendSightArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("推荐景点文章")
    @ApiOperationSupport(order = 300)
    public JsonResult setIsRecommendSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        sightArticleService.setIsRecommendSightArticle(ids);
        return JsonResult.ok();
    }

    @PostMapping("/setIsNotRecommendSightArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("不推荐景点文章")
    @ApiOperationSupport(order = 400)
    public JsonResult setIsNotRecommendSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        sightArticleService.setIsNotRecommendSightArticle(ids);
        return JsonResult.ok();
    }

    @PostMapping("/setCheckStatePass")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("通过景点文章审核")
    @ApiOperationSupport(order = 500)
    public JsonResult setCheckStatePass(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        sightArticleService.setCheckStatePass(ids);
        return JsonResult.ok();
    }

    @PostMapping("/setCheckStateNotPass")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("拒绝景点文章审核")
    @ApiOperationSupport(order = 600)
    public JsonResult setCheckStateNotPass(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        sightArticleService.setCheckStateNotPass(ids);
        return JsonResult.ok();
    }

    @PostMapping("/setSort")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("设置景点文章排序")
    @ApiOperationSupport(order = 700)
    public JsonResult setSort(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,Long id,Integer sort) {
        sightArticleService.setSort(id,sort);
        return JsonResult.ok();
    }

    @GetMapping("/listSortArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("查看景点文章排序")
    @ApiOperationSupport(order = 800)
    public JsonResult listSortArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(sightArticleService.listSortArticle());
    }

    @GetMapping("/listCheckStateArticle")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("查看景点未审核文章")
    @ApiOperationSupport(order = 900)
    public JsonResult listCheckStateArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(sightArticleService.listCheckStateArticle());
    }


}
